package com.ruoyi.project.business.machine.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.machine.domain.YlMachine;
import com.ruoyi.project.business.machine.service.IYlMachineService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 售货机Controller
 * 
 * @author ruoyi
 * @date 2021-04-26
 */
@Controller
@RequestMapping("/business/machine")
public class YlMachineController extends BaseController
{
    private String prefix = "business/machine";

    @Autowired
    private IYlMachineService ylMachineService;

    @RequiresPermissions("business:machine:view")
    @GetMapping()
    public String machine()
    {
        return prefix + "/machine";
    }

    /**
     * 查询售货机列表
     */
    @RequiresPermissions("business:machine:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YlMachine ylMachine)
    {
        startPage();
        List<YlMachine> list = ylMachineService.selectYlMachineList(ylMachine);
        return getDataTable(list);
    }

    /**
     * 导出售货机列表
     */
    @RequiresPermissions("business:machine:export")
    @Log(title = "售货机", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YlMachine ylMachine)
    {
        List<YlMachine> list = ylMachineService.selectYlMachineList(ylMachine);
        ExcelUtil<YlMachine> util = new ExcelUtil<YlMachine>(YlMachine.class);
        return util.exportExcel(list, "售货机数据");
    }

    /**
     * 新增售货机
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存售货机
     */
    @RequiresPermissions("business:machine:add")
    @Log(title = "售货机", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YlMachine ylMachine)
    {
        return toAjax(ylMachineService.insertYlMachine(ylMachine));
    }

    /**
     * 修改售货机
     */
    @GetMapping("/edit/{machineId}")
    public String edit(@PathVariable("machineId") String machineId, ModelMap mmap)
    {
        YlMachine ylMachine = ylMachineService.selectYlMachineById(machineId);
        mmap.put("ylMachine", ylMachine);
        return prefix + "/edit";
    }

    /**
     * 修改保存售货机
     */
    @RequiresPermissions("business:machine:edit")
    @Log(title = "售货机", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YlMachine ylMachine)
    {
        return toAjax(ylMachineService.updateYlMachine(ylMachine));
    }

    /**
     * 删除售货机
     */
    @RequiresPermissions("business:machine:remove")
    @Log(title = "售货机", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ylMachineService.deleteYlMachineByIds(ids));
    }
}
